﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestEfxScript : MonoBehaviour {
	public static TestEfxScript instance;
    public Sprite[] sprites;
    public EffectScript efxPrefab;
    public BezierEffectScript efxBezierPrefab;
	private void Awake()
	{
		instance = this;
	}
    void Start () {
        efxPrefab.CreatePool(10);
        efxBezierPrefab.CreatePool(10);
         }
    void TestEfx(Vector3 pos)
    {
		var e = efxPrefab.Spawn (transform).SetTime (1)
                         .SetSprite(sprites[0])
                         .SetTime(Random.Range(1f, 3f))
                         .SetDestroyOnDone(true)
                         .SetOnComplete(() => { Debug.Log("animation done!"); });

        var d1 = new EffectData
        {
            position = pos,
            scale = Vector3.one,
            rotate = 0,
            alpha = 1,
        };
        var d2 = new EffectData
        {
            position = pos + Vector3.up * 3,
            scale = Vector3.zero,
            rotate = 180,
            alpha = 0,
        };
        e.Run(d2, d1);
    }
	public static void SpawnBezier(Vector3 pos)
	{

		instance.TestBezierEfx (pos);
	}
    void TestBezierEfx(Vector3 pos)
    {

        var e = efxBezierPrefab.Spawn(transform).SetTime(1);
		var a = new Vector3 (Camera.main.ScreenToWorldPoint (new Vector3 (Screen.width * 0.3f, 0, 0)).x,
			Camera.main.ScreenToWorldPoint (new Vector3 (0, Screen.height*0.95f, 0)).y, 0
		);
        var d1 = new EffectData
        {
            position = pos,
            scale = Vector3.one * 2,
            rotate = 0,
            alpha = 0,
        };
        var d2 = new EffectData
        {

			position =a,
            scale = Vector3.one * 0.5f,
            rotate = 180,
            alpha = 1,
        };
        e.Run(d1, d2);
    }
    void TestPositionEfx(Vector3 pos)
    {
        var e = efxPrefab.Spawn(transform);
        e.RunPosition(pos, pos + Vector3.one * 5);
		e.SetOnComplete(()=>Debug.Log("OK"));
    }
    void TestScaleEfx(Vector3 pos)
    {
        var e = efxPrefab.Spawn(transform);
        e.RunScale(pos, Vector3.one * 5, Vector3.zero);
    }
    void TestRotateEfx(Vector3 pos)
    {
        var e = efxPrefab.Spawn(transform).SetSprite(sprites[1]);
        e.RunRotate(pos, 0, 180);
    }
    void TestAlphaEfx(Vector3 pos)
    {
        var e = efxPrefab.Spawn(transform).SetSprite(sprites[0]);
        e.RunAlpha(pos, 0, 1);
    }
}
